package ldh.serialize.type;

import ldh.serialize.BinarySerialized;
import ldh.serialize.io.ByteBuf;
import ldh.serialize.util.SerializedUtil;

import java.io.IOException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class LocalDateSerialized implements BinarySerialized<LocalDate> {

	@Override
	public void write(ByteBuf out, LocalDate localDate) throws IOException {
		Long time = null;
		if (localDate != null) {
			time  = localDate.toEpochDay();
		}
		SerializedUtil.writeLong(out, time);
	}

	@Override
	public LocalDate read(ByteBuf in) throws IOException {
		Long time = SerializedUtil.readLong(in);
		if (time == null) {
			return null;
		}
		LocalDate longToLocalDate = LocalDate.ofEpochDay(time);
		return longToLocalDate;
	}

	@Override
	public Class<LocalDate> getClassType() {
		return LocalDate.class;
	}

}
